///*
//package com.ruicar.afs.cloud.bizcommon.voucher.component;
//
//import com.baomidou.mybatisplus.core.toolkit.Wrappers;
//import com.ruicar.afs.cloud.bizcommon.voucher.dto.VoucherFlowInfoDto;
//import com.ruicar.afs.cloud.bizcommon.voucher.entity.VoucherFlowInfo;
//import com.ruicar.afs.cloud.bizcommon.voucher.enums.VoucherStatusEnum;
//import com.ruicar.afs.cloud.bizcommon.voucher.service.VoucherFlowInfoService;
//import com.ruicar.afs.cloud.bizcommon.voucher.service.VoucherFlowService;
//import com.ruicar.afs.cloud.common.core.constant.CommonConstants;
//import com.ruicar.afs.cloud.common.core.service.ServiceInfo;
//import com.ruicar.afs.cloud.common.core.util.IResponse;
//import com.ruicar.afs.cloud.common.core.util.SpringContextHolder;
//import com.ruicar.afs.cloud.common.data.lock.anno.Lock;
//import lombok.AllArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.boot.context.event.ApplicationReadyEvent;
//import org.springframework.context.ApplicationListener;
//import org.springframework.stereotype.Component;
//
//import java.util.List;
//import java.util.concurrent.Executors;
//import java.util.concurrent.ScheduledExecutorService;
//import java.util.concurrent.TimeUnit;
//
//@Component
//@Slf4j
//@AllArgsConstructor
//public class VoucherSendPublishComponent implements ApplicationListener<ApplicationReadyEvent> {
//    private static final ScheduledExecutorService EXECUTOR_SERVICE = Executors.newSingleThreadScheduledExecutor();
//    private final VoucherFlowInfoService voucherFlowInfoService;
//    private final VoucherFlowService voucherFlowService;
//    @Override
//    public void onApplicationEvent(ApplicationReadyEvent event) {
//        schedule();
//    }
//
//    @Lock(keyConstant="lock-afs-voucher-send-publish",keys = "#serviceName")
//    public void publish(){
//        try {
//           //加载未发送和发送失败的
//            List<VoucherFlowInfo> voucherFlowInfos = voucherFlowInfoService.list(Wrappers.<VoucherFlowInfo>lambdaQuery().eq(VoucherFlowInfo::getStatus, VoucherStatusEnum.NOT_SEND).or()
//                    .eq(VoucherFlowInfo::getStatus, VoucherStatusEnum.FAIL_SEND).orderByAsc(VoucherFlowInfo::getCreateTime));
//            for (VoucherFlowInfo voucherFlowInfo : voucherFlowInfos) {
//                VoucherFlowInfoDto dto =VoucherFlowInfoDto.convertFromInfo(voucherFlowInfo);
//                IResponse iResponse = voucherFlowService.send(dto);
//                if (CommonConstants.SUCCESS.equals(iResponse.getCode())) {
//                    voucherFlowInfo.setStatus(VoucherStatusEnum.SUCCESS_SEND);
//                    voucherFlowInfoService.updateById(voucherFlowInfo);
//                }else{
//                    log.error( "流水号：{},凭证流水数据推送失败！,错误信息：{}",dto.getTransNo(),iResponse.getMsg());
//                    voucherFlowInfo.setStatus(VoucherStatusEnum.FAIL_SEND);
//                    voucherFlowInfoService.updateById(voucherFlowInfo);
//                }
//            }
//        }catch (Throwable e){
//            log.error("凭证流水数据推送失败",e);
//        }
//    }
//
//    private void schedule(){
//        //每3s 检测发布处理流水
//        EXECUTOR_SERVICE.scheduleWithFixedDelay(()->{
//            SpringContextHolder.getBean(VoucherSendPublishComponent.class).publish();
//        },2,3, TimeUnit.SECONDS);
//
//    }
//}
//*/
